Why does `Array.length`, `Function.length`, `String.length`, etc return 1?

Posted by zealoushacker on Stack Overflow See other posts from Stack Overflow or by zealoushacker
Published on 2012-10-30T20:45:49Z Indexed on 2012/10/30 23:01 UTC
Read the original article Hit count: 86

Filed under:

While teaching my JavaScript class yesterday, my students and I came across some interesting functionality that I thought might be worth capturing in a question and the answer I've come to.

Typing Array.length in the JS console in chrome returns 1.

Likewise, Function.length returns 1. This is important because:

Every function in JavaScript is actually a Function object. (MDN JS Ref: Function)

Thus, Object.length and likely all other native objects will and should return 1 as the value of the length property.

So, finally why is this behavior occurring?

© Stack Overflow or respective owner

Related posts about JavaScript